|
Stepper motor control via parallel
port |
To
better understand the circuit, one needs to have some
knowl- edge of electronics, computer programming, and
the computer’s parallel port. You will of course need
a computer, 12-volt power supply (preferably a battery
eliminator), stepper motor, ULN2003 chip, and some
connecting wires. The circuit can be easily
assembled on a breadboard. It is very important that you
work with the smallest stepper motor available in the
market, such as the one used in a floppy drive. If you
go in for the large ones used in CNC machines, there is
a chance of damaging the PC’s parallel port. The second
thing to mention is that the colours of the wires of the
stepper motor are non-standard. computer to communicate
with the outside world. The parallel port is
generally used to interface printers, but we have used
it to interface the stepper motor. The parallel port
consists of 25 pins, but it can only transmit 8 bits of
data at a time. The reason for the large number of pins
is that every data pin has its own ground return pin.
There are other pins for various other functions. We
have used only four data pins and a ground pin. The
functions of the various pins are given in Table I. Pins
2 through 9 are data pins. Here, we will use data pins 2
to 5, corresponding to data bits D0 through D3 of port
378(hex) for LPT1 or 278(hex) for LPT2. Also, pin 25 is
used as the ground pin. The PC’s parallel port cannot
sink much current. At the most, it can handle a few
milliamperes. So, if the parallel port is connected
directly to an electrical device, it will damage the
parallel port. Thus, we need a current amplifier in
between the parallel port and the electrical device. The
ULN2003, used precisely for this purpose, has an array
of Darlington transistor pairs. A Darlington
configuration is a way of connecting two transistors in
order to amplify current to many times the input current
value. The stepper motor has various advantages over
other motors, as far as controlling by a computer is
concerned. It includes high precision of angular
movement, speed of rotation, and high moving and holding
torque. It comes in various flavours. We are dealing
with unipolar permanent magnet stepper motor that has
four coils arranged as follows: Terminals 1 and 2 are
common terminals (connected to ground or the positive
supply) and the other four terminals are fed to the
appropriate signals. When a proper signal is applied,
the shaft turns by a specific angle, called the step
resolution of the motor. On continuous application of
the same signal, the shaft stays in the same position.
Rotation occurs only when the signal is changed in a
proper sequence. There are three modes of operation of a
stepper motor, namely, single-coil excitation mode,
dual-coil excitation mode, and half-step modes. •
Single-coil excitation. Each coil is energised
successively in a rotary fashion. If the four coils are
assumed to be in a horizontal plane, the bit pattern
will be 0001, 0010, 0100, 1000, and 0001. • Dual-coil
excitation. Here, two adjacent coils are energised
successively in a rotary fashion. The bit pattern will
be 0011, 0110, 1100, 1001, and 0011. • Half-step
mode. Here, the stepper motor operates at half the given
step resolution. The bit pattern is 0001, 0011, 0010,
0110, 0100, 1100, 1000, 1001, and 0001. Two software
control programs, one for DOS and another for Linux, are
included here. The program for DOS can be used to run
the motor in full- or half-step mode, or in single-coil
or double-coil excitation mode. (EFY Lab note. The
method used at EFY for correct identification of the
stepper motor coils involved measuring the windings’
resistance as well as their continuity in ohmsx1 scale,
using any good multimeter. The resistance of individual
coils with respect to the middle points will roughly be
half the resistance of the combined coil pairs (L1 and
L2 or L3 and L4 in the figure). After having identified
the coils in this fashion, connect them to the circuit
as shown in the figure. Now, if the sequence of input to
the coils happens to be wrong, the shaft, instead of
moving (clockwise or anti-clockwise), will only vibrate.
This can be corrected by trial and error, by
interchanging connection to the coils. The output
waveforms for full-step single-coil mode, as seen on the
oscilloscope, are shown in the figure.)
|
| Pin
No (D-type 25) |
Signal
|
Direction
(In/Out |
Register |
Hardware Inverted |
|
1 |
Strobet |
In/Out |
Control |
Yes |
|
2 thru 9 |
D0 thru |
Out |
Data |
— |
|
11 |
Busy |
In |
Status |
Yes |
|
12 |
PE |
In |
Status |
— |
|
13 |
Select |
In |
Status |
— |
|
14 |
AFeed |
Out |
Control |
Yes |
|
15 |
Error |
In |
Status |
— |
|
16 |
Initialise |
Control |
Out |
— |
|
17 |
SLCT |
Out |
Control |
Yes
(Printer) | |
| DOS
program |
| #include #include #define
FULLSTEP_SINGLECOIL //#define FULLSTEP_DOUBLECOIL
//#define HALFSTEP unsigned char
fullstep_singlecoil_val[]={1,2,4,8}; unsigned char
fullstep_doublecoil_val[]={3,6,12, 9}; unsigned char
halfstep_val[]={8,12,4,6,2,3,9}; void main() { unsigned
int i=0; while(!kbhit()) { #ifdef FULLSTEP_SINGLECOIL
outportb(0x378,fullstep_singlecoil_val[i%sizeof
(fullstep_singlecoil_val)]); #elif
defined(FULLSTEP_DOUBLECOIL)
outportb(0x378,fullstep_doublecoil_val[i%sizeof
(fullstep_doublecoil_val)]); #elif defined(HALFSTEP)
outportb(0x378,halfstep_val[i%sizeof(halfstep_val)]);
#endif delay(10); i++; if(i==65535u) i=0; }
outportb(0x378,0); } Compile and run the program under
any compiler like turboc for dos or Borland
C++. |
| LINUX
program |
| #include #include #include
//#define FULLSTEP_SINGLECOIL //#define
FULLSTEP_DOUBLECOIL #define HALFSTEP unsigned char
fullstep_singlecoil_val[]={1,2,4,8}; unsigned char
fullstep_doublecoil_val[]={3,6,12, 9}; unsigned char
halfstep_val[]={8,12,4,6,2,3,9}; void main() { unsigned
int i=0; if(ioperm(0x378,1,1)==-1) exit(1); while(1) {
#ifdef FULLSTEP_SINGLECOIL
outb(fullstep_singlecoil_val[i%sizeof(fullstep_
singlecoil_val)],0x378); #elif
defined(FULLSTEP_DOUBLECOIL)
outb(fullstep_doublecoil_val[i%sizeof(fullstep_
doublecoil_val)],0x378); #elif defined(HALFSTEP)
outb(halfstep_val[i%sizeof(halfstep_val)],0x378); #endif
usleep(5000); i++; if(i==65535u) i=0; } outb(0,0x378); }
Compile and run the program as follows: #gcc –O6 –o
motor motor.c #./motor The –O6 flag is necessary for
using the ‘outb’
function. | | |
Click on the Image for its larger
version


|